﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using AMatysiak.Comparers;
using System.Collections;
using System;

namespace AMatysiakTest.Comparers
{
    [TestClass]
    public class AlphaNumComparerTest
    {
        private const int BIGGER = 1;
        private const int EQUAL = 0;
        private const int SMALLER = -1;

        private IComparer comparer = new AlphaNumComparer();
        
        [TestMethod]
        public void compareEmpties()
        {
            string empty = "";

            int result = comparer.Compare(empty, empty);

            Assert.AreEqual(EQUAL, result);
        }

        [TestMethod]
        public void compareEmptyWithNotEmpty()
        {
            string empty = "";
            string notEmpty = "a";

            int result = comparer.Compare(empty, notEmpty);

            Assert.AreEqual(SMALLER, result);
        }

        [TestMethod]
        public void compareNotEmptyWithEmpty()
        {
            string notEmpty = "a";
            string empty = "";

            int result = comparer.Compare(notEmpty, empty);

            Assert.AreEqual(BIGGER, result);
        }

        [TestMethod]
        public void compareEqual()
        {
            string equal = "adam";

            int result = comparer.Compare(equal, equal);

            Assert.AreEqual(EQUAL, result);
        }

        [TestMethod]
        public void compareWordToNumber()
        {
            string word = "adam";
            string number = "1234";

            int result = comparer.Compare(word, number);

            Assert.AreEqual(BIGGER, result);
        }

        [TestMethod]
        public void compareWordToWordWithDigit()
        {
            string word = "adam";
            string wordWithDigit = "adam8";

            int result = comparer.Compare(word, wordWithDigit);

            Assert.AreEqual(SMALLER, result);
        }

        [TestMethod]
        public void compareThreeWordsInAlphaNumericalWay()
        {
            string word1 = "adam1";
            string word2 = "adam2";
            string word3 = "adam12";
            
            int result12 = comparer.Compare(word1, word2);
            Assert.AreEqual(SMALLER, result12);

            int result13 = comparer.Compare(word1, word3);
            Assert.AreEqual(SMALLER, result13);

            int result23 = comparer.Compare(word2, word3);
            Assert.AreEqual(SMALLER, result23);

            int result21 = comparer.Compare(word2, word1);
            Assert.AreEqual(BIGGER, result21);

            int result31 = comparer.Compare(word3, word1);
            Assert.AreEqual(BIGGER, result31);

            int result32 = comparer.Compare(word3, word2);
            Assert.AreEqual(BIGGER, result32);
        }

        [TestMethod]
        public void compareWordToEmpty()
        {
            string word = "adam";
            string empty = "";

            int result = comparer.Compare(word, empty);

            Assert.AreEqual(BIGGER, result);
        }

        [TestMethod]
        public void compareTwoInts()
        {
            int int1 = 5;
            int int2 = 44;

            int result = comparer.Compare(int1, int2);

            Assert.AreEqual(SMALLER, result);
        }

        [TestMethod]
        public void compareTwoDoubles()
        {
            double double1 = 5.25;
            double double2 = 52.5;

            int result = comparer.Compare(double1, double2);

            Assert.AreEqual(SMALLER, result);
        }

        [TestMethod]
        public void compareTwoDateTimes()
        {
            DateTime dt1 = DateTime.Now;
            DateTime dt2 = DateTime.Now.AddDays(20);

            int result = comparer.Compare(dt1, dt2);

            Assert.AreEqual(SMALLER, result);
        }

        [TestMethod]
        public void compareBools()
        {
            bool bool1 = false;
            bool bool2 = true;

            int result = comparer.Compare(bool1, bool2);

            Assert.AreEqual(SMALLER, result);
        }

        [TestMethod]
        public void ultimateTest()
        {
            ArrayList list = new ArrayList()
            {
                "",
                "adam",
                "adam5",
                "adam2",
                "adam22",
                "adam12",
                "mat",
                "5",
                "12",
                "",
                "a54",
                "a54b",
                "a54a"
            };

            ArrayList properList = new ArrayList()
            {
                "",
                "",
                "5",
                "12",
                "a54",
                "a54a",
                "a54b",
                "adam",
                "adam2",
                "adam5",
                "adam12",
                "adam22",
                "mat"
            };

            list.Sort(comparer);

            for(int i = 0; i < list.Count; i++)
                Assert.AreEqual(properList[i], list[i]);
        }
    }
}
